package pl.koziczak.knowledgeintegration.xml;

import java.io.File;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;

import pl.koziczak.knowledgeintegration.exception.KnowledgeIntegrationException;

public class XMLWriter {
	

	public void writeXMLFile(Document xmlDocument, File file) throws KnowledgeIntegrationException {
		Source source = new DOMSource(xmlDocument);
		
		Result result = new StreamResult(file);
		
		Transformer xformer;
		try {
			xformer = TransformerFactory.newInstance().newTransformer();
			xformer.transform(source, result);
		} catch (TransformerConfigurationException e) {
			throw new KnowledgeIntegrationException(e);
		} catch (TransformerFactoryConfigurationError e) {
			throw new KnowledgeIntegrationException(e);
		} catch (TransformerException e) {
			throw new KnowledgeIntegrationException(e);
		}

	}
}
